/** 
 * @author lilin
 * @date 2012-5-10 下午4:36:47 
 * @annotation
 */
package com.epoint.mobileoa.bizlogic.mobileoa;

import java.util.HashMap;
import java.util.List;

import android.os.Message;

import com.epoint.mobileoa.bizlogic.ConfigKey;
import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.bizlogic.Task;
import com.epoint.mobileoa.datanalysis.XMLHelp;
import com.epoint.mobileoa.db.DBHelp;
import com.epoint.mobileoa.http.HttpHelp;
import com.epoint.mobileoa.model.FrameOpinion;
import com.epoint.mobileoa.tools.LogHelp;
import com.epoint.mobileoa.tools.StringHelp;

/**
 * @author lilin
 * @date 2012-5-10 下午4:36:47
 * @annotation 获取意见模版
 */
public class OpinionTask extends Task {

	public OpinionTask(SuperView con, HashMap<String, Object> param) {
		super(con, param);
	}

	@Override
	public void exectue(Message mess) throws Exception {
		String userguid = DBHelp.getConfigValue(getCon(), ConfigKey.userguid);
		String seamurl = getCon().fp.getSeamurl()
				+ "?requestType=getopiniontemplate&userguid=" + userguid;
		String bs = HttpHelp.getHttpBack(seamurl);
		if (bs.indexOf(HttpHelp.RESPONSEINFO_SUCCESS) > -1) {
			String commonString = "";
			if (bs.contains("<commons")) {
				String xml = "<item>" + StringHelp.getXMLAtt(bs, "commons")
						+ "</item>";
				List<FrameOpinion> list = XMLHelp.JieXiOpinion(xml);
				for (int i = 0; i < list.size(); i++) {
					FrameOpinion frameOpinion = list.get(i);
					commonString += frameOpinion.opinionText + ";";
				}
			}
			String personString = "";
			if (bs.contains("<persons")) {
				String xml = "<item>" + StringHelp.getXMLAtt(bs, "persons")
						+ "</item>";
				List<FrameOpinion> list2 = XMLHelp.JieXiOpinion(xml);
				for (int i = 0; i < list2.size(); i++) {
					FrameOpinion frameOpinion = list2.get(i);
					personString += frameOpinion.opinionText + ";";
				}
			}
			HashMap<String, String> param = new HashMap<String, String>();
			param.put("type", "opinion");
			param.put("bs", commonString + "," + personString);
			setMessageToRefreshUI(mess, getCon(), param);
		} else {
			setMessageToRefreshUI(mess, getCon(), "false");
		}
	}

}
